//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _ATTRACCESSORS_H
#define _ATTRACCESSORS_H
#include "uierror.h"
//
template<typename C,typename T>
class AttrAccessor {
public:
   AttrAccessor() {;}
   virtual ~AttrAccessor() {;}
   virtual UiError get(const C*, T&) const = 0;
   virtual UiError set(C*, T) const = 0;
};
//
template<typename C,typename T>
class GetSetFuncAccessor : public AttrAccessor<C,T> {
public:
   typedef T (C::*GetFn)(void) const;
   typedef void (C::*SetFn)(T);
   GetSetFuncAccessor(GetFn getf, SetFn setf) {get_func = getf; set_func = setf;}
   ~GetSetFuncAccessor() {;}
   UiError get(const C *obj, T &val) const {val = (obj->*get_func)(); return UiError();}
   UiError set(C *obj, T newval) const {(obj->*set_func)(newval); return UiError();}
private:
   GetFn get_func;
   SetFn set_func;
};
//
/*template<class C,class T>
class GetSetRefFuncAccessor : public AttrAccessor<C,T> {
public:
   typedef T& (C::*GetFn)(void) const;
   typedef void (C::*SetFn)(const T&);
   GetSetFuncAccessor(GetFn getf, SetFn setf) {get_func = getf; set_func = setf;}
   ~GetSetFuncAccessor() {;}
   UiError get(const C *obj, T &val) {val = (obj->*get_func)(); return UiError();}
   UiError set(C *obj, const T &newval) {(obj->*set_func)(newval); return UiError();}
private:
   GetFn get_func;
   SetFn set_func;
};*/
#endif //_ATTRACCESSORS_H
